<script type="text/javascript">

    // Function for reload Sub Departemen option, depend on selected Departemen
    var f_set_combo_sub_departemen = function(){
        var ls_departemen_code    = $('#id_departemen_fk').val();
        var ls_sub_departemen_code        = '<?php echo $data['id_sub_departemen_fk']; ?>';

        $('#id_sub_departemen_fk').setCombo({ 
            data: gs_path+'/hrd_karyawan/comboSubDepartemen/?id_departemen='+ls_departemen_code, 
            value: ls_sub_departemen_code 
        });
    };
    
    var f_set_combo_jurusan = function(){
        var ls_jenjang_code    = $('#id_jenjang_pendidikan_fk').val();
        var ls_jurusan_code        = '<?php echo $data['id_jurusan_pendidikan_fk']; ?>';

        $('#id_jurusan_pendidikan_fk').setCombo({ 
            data: gs_path+'/hrd_karyawan/comboJurusan/?id_jenjang='+ls_jenjang_code, 
            value: ls_jurusan_code 
        });
    };

    var f_set_pangkat = function(){
        var ls_sub_departemen_code = $('#id_sub_departemen_fk option:selected').val();
        
        jQuery.ajax({
          url: gs_path+'/hrd_sub_departemen/ambil_per_id/'+ls_sub_departemen_code,
          dataType: 'json',
          success: function(data, textStatus, xhr) {
            //called when successful
            $('#id_pangkat_fk').val(data.nama_pangkat);
            console.log(data);
          },
          error: function(xhr, textStatus, errorThrown) {
            //called when there is an error
            console.log("errror");
          }
        });
     }

    $(document).ready(function() {
        // Setup Form
        $('#form_master').setupForm([
            { name: 'id_karyawan_pk', type: 'text', size: 'medium', maxlength: 10, noempty:true },
            { name: 'nama_karyawan', type: 'text', size: 'medium', maxlength: 100, noempty:true },
            { name: 'nama_pelamar', type: 'text', maxlength: 100, noempty:true },
            { name: 'ket_mode', type: 'text', maxlength: 100, noempty:true },
            { name: 'status_kontrak_pekerjaan', type: 'text' },
            { name: 'sk_pengangkatan', type: 'text', size: 'medium' },
            { name: 'id_pangkat_fk', type: 'text', size: 'short' },
            { name: 'id_jenjang_pendidikan_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listJenjang)); ?>, onChange:f_set_combo_jurusan },
            { name: 'id_jurusan_pendidikan_fk', size: 'medium', data:[] },
            { name: 'id_lokasi_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listLokasi)); ?> },
            { name: 'id_divisi_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listDivisi)); ?> },
            { name: 'id_departemen_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listDepartemen)); ?>, onChange:f_set_combo_sub_departemen },
            { name: 'id_sub_departemen_fk', size: 'medium', data:[], onChange:f_set_pangkat },
            { name: 'id_jabatan_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listJabatan)); ?> },
            // { name: 'id_status_kontrak_fk', size: 'medium', data:<?php echo json_encode($listStatusKontrak); ?> },
            { name: 'id_status_kerja_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listStatusKerja)); ?> },
            { name: 'id_cost_center_fk', size: 'medium', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listCostCenter)); ?> },
            { name: 'id_grub_absen_fk', size: 'small', data:<?php echo json_encode(array_merge(array(array('value'=>'','display'=>'')),$listGrubAbsen)); ?> },
            { name: 'status_piket', size: 'small', data:[{'value':'','display':''}, {'value':'0','display':'Ya'}, {'value':'1','display':'Tidak'}] },
            { name: 'no_finger_scan', type: 'text' },
            { name: 'tgl_bergabung', type: 'date' },
            // { name: 'id_poin_gaji_fk', type: 'text', size:'short', data:<?php echo json_encode($listPoinGajiKontrak); ?> }
            { name: 'id_poin_gaji_fk', type: 'lov', size: 'short',
                onClearButton:function(){
                    $(this).setval(''); 
                },
                onActionButton:function(){ 
                    LOVHrdPoinGajiKontrak({ onSelect:function(row){ 
                        $('#id_poin_gaji_fk').setval(''); 
                        $('#id_poin_gaji_fk').setval(row.id_poin_gaji_pk); 
                        $('#gaji').setval(row.gaji); 
                    } });
                }
            },
            { name: 'gaji', type: 'numeric', size: 'short' },
        ], 
            <?php echo json_encode($data); ?>
        );

        $('#ket_mode').val('<?php echo $mode; ?>');
        $('#status_kontrak_pekerjaan').val(1);

        // Set Hidden Object
        $('#nama_pelamar').hide();
        $('#ket_mode').hide();
        $('#status_kontrak_pekerjaan').hide();

        // Setup combo with null value
        // $('#id_pangkat_fk').setCombo({ data: <?php echo json_encode($listPangkat); ?> });
        
        f_set_combo_sub_departemen();
        f_set_combo_jurusan();
        // f_set_pangkat();
        
        <?php if($mode=="edit"){ ?>
        $('#id_karyawan_pk').readonly();
        // $('#tgl_bergabung').readonly();
        <?php } ?>
        $('#gaji').readonly();
        $('#id_pangkat_fk').readonly();
        
        // Set Action Button
        var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
                            $('#form_master').submitForm(   '/'+controller+'/ajax_post', 
                                {   
                                    onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/edit_kontrak_pekerjaan/?id_karyawan_pk='+(oData.genid!='' ? oData.genid : $('#id_karyawan_pk').getval())); }
                                } 
                            ); 
                        }},
                       { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/kontrak_pekerjaan'); } }];
        setAction(buttons);
        
        // Create Tab
        $('#tt').tabs({ border:false });  
        
        // Focus at First Object
        $('#form_master').focusFirst();

        // Set Nama Karyawan dari Nama Pelamar
        var namaPelamar = $('#nama_pelamar').val();
        if (nama_pelamar != '') {
            $('#nama_karyawan').val(namaPelamar);
        }
    });
</script>

<div id="form_master_message" style="display:none;"></div>

<table class="tb_form" style="display:none; width:100%; " cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="label">NIK</td>
        <td><input id="id_karyawan_pk" /> <input id="ket_mode" /> <input id="status_kontrak_pekerjaan" /> </td>
        <td colspan="2" rowspan="8">
            <!-- Foto : <img src="/primkokas/files/people.png" width="150" height="200" border="3" style="float:right;">  -->
        </td>
    </tr>
    <tr>
        <td class="label">Nama</td>
        <td><input id="nama_karyawan" /><input id="nama_pelamar" /></td>
    </tr>
    <tr>
        <td class="label">SK Pekerjaan</td>
        <td><input id="sk_pengangkatan" /></td>
    </tr>
    <tr>
        <td class="label">Jenjang - Jurusan Pendidikan</td>
        <td><input id="id_jenjang_pendidikan_fk" /> - <input id="id_jurusan_pendidikan_fk" /></td>
    </tr>
    <!-- <tr>
        <td class="label">Lokasi Kantor</td>
        <td><input id="id_lokasi_fk" /></td>
    </tr> -->
    <tr>
        <td class="label">Divisi</td>
        <td><input id="id_divisi_fk" /></td>
    </tr>
    <tr>
        <td class="label">Unit Kerja - Jabatan</td>
        <td><input id="id_departemen_fk" /> - <input id="id_sub_departemen_fk" /></td>
    </tr>
    <tr>
        <td class="label">Pangkat</td>
        <td>
        <input id="id_pangkat_fk" />
        <!-- <select id="id_pangkat_fk" name="id_pangkat_fk" class="textfield medium"></select> -->
        </td>
    </tr>
    <tr>
        <td class="label">Status Kerja</td>
        <td><input id="id_status_kerja_fk" /></td>
    </tr>
    <tr>
        <td class="label">Cost Center</td>
        <td><input id="id_cost_center_fk" /></td>
        <td colspan="2">Poin Gaji : <input id="id_poin_gaji_fk" /></td>
    </tr>
    <tr>
        <td class="label">No Finger Scan</td>
        <td><input id="no_finger_scan" /></td>
        <td colspan="2">Nilai Gaji : <input id="gaji" /></td>
    </tr>
    <!-- <tr>
        <td class="label">Grub Absen</td>
        <td><input id="id_grub_absen_fk" /></td>
    </tr> -->
    <tr>
        <td class="label">Tanggal Bergabung</td>
        <td><input id="tgl_bergabung" /></td>
        <td colspan="2">Grup Absen : <input id="id_grub_absen_fk" /></td>
        <!-- <td colspan="2">Status Piket : <input id="status_piket" /></td> -->
    </tr>
</table>

<div id="tt" class="easyui-tabs" style="min-height:400px;"> 

    <div title="Detail Kontrak" style="overflow:auto;padding:10px;">  
        <?php require_once('detail_kontrak_pekerjaan.php'); ?>
        <?php if ($mode=="edit"): ?>
            <?php require_once('histori_kontrak.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data histori Kontrak!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Personal Info" style="overflow:auto;padding:10px;">  
        <?php require_once('detail_personal.php'); ?>
    </div>
    
    <div title="Keuangan Info" style="overflow:auto;padding:10px;">  
        <?php require_once('detail_keuangan.php'); ?>
    </div>

    <div title="Keluarga" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_keluarga.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Keluarga!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Pendidikan" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_pendidikan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Detail Pendidikan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Kenaikan Gaji" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('kenaikan_gaji.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data kenaikan gaji!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Penghargaan" style="overflow:auto;padding:10px;">  
        <?php if ($mode=="edit"): ?>
            <?php require_once('detail_penghargaan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Penghargaan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Peringatan" style="overflow:auto;padding:10px;">  
       <?php if ($mode=="edit"): ?>
            <?php require_once('detail_peringatan.php'); ?>
        <?php else: ?>
            <center><h4>Lakukan Save terlebih dahulu untuk memasukkan data Peringatan!!</h4></center>
        <?php endif ?>
    </div>

    <div title="Info Tambahan" style="overflow:auto;padding:10px;">  
        <?php require_once('detail_tambahan.php'); ?>
    </div>
</div>